<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Mstaticinfo extends MY_Model
{
    public function __construct()
    {
        parent::__construct();
    }
    
    public function getLogoGpeople()
    {
        $data = $this->db->query("SELECT `content` FROM `options` WHERE `tags` = 'logo_gpeople'")->row_object();
        return $data->content; 
    }
    public function logoGpeopleDb($img)
    {
        if(!in_array($img, array(null,'')))
        {
            $data = array(
                'content' => $img
            );
            
            $this->db->update('options', $data, "tags = 'logo_gpeople'");
            $this->db->update('options', array('content' => time()), "tags = 'time_update_api_static'");
            return 200;
        }
    }
    
    public function getFanpage()
    {
        $fanpage = $this->db->query("SELECT `content` FROM options WHERE `tags` = 'fanpage'")->row_object();
        $hotline = $this->db->query("SELECT `content` FROM options WHERE `tags` = 'hotline'")->row_object();
        return array('fanpage' => $fanpage->content, 'hotline' => $hotline->content);
    }
    public function fanpageFacebookDb($url,$hotline)
    {
        $data = array(
            'content' => $url
        );
        $hotline = array(
            'content' => $hotline
        );
        $this->db->update('options', $data, "tags = 'fanpage'");
        $this->db->update('options', $hotline, "tags = 'hotline'");
        $this->db->update('options', array('content' => time()), "tags = 'time_update_api_static'");
        return 200;
    }
	
	public function getDistance()
	{
		return $this->db->query("SELECT `content` FROM options WHERE `tags` = 'distance'")->row_object();
	}
	
	public function distanceDb($distance){
		$this->db->update('options', array('content' => $distance), "tags = 'distance'");
		$this->db->update('options', array('content' => time()), "tags = 'time_update_api_static'");
		return 200;
	}
	
	public function getUrlHomeIcook()
	{
		$urlhomeicook= $this->db->query("SELECT `content` FROM options WHERE `tags` = 'urlhomeicook'")->row_object();
        $link_down_app = $this->db->query("SELECT `content` FROM options WHERE `tags` = 'link_down_app'")->row_object();
        return (object)array('urlhomeicook' => $urlhomeicook->content, 'link_down_app' => $link_down_app->content);
	}
	
	public function UrlHomeIcookDb($urlhomeicook, $link_down_app){
		$this->db->update('options', array('content' => $urlhomeicook), "tags = 'urlhomeicook'");
        $this->db->update('options', array('content' => $link_down_app), "tags = 'link_down_app'");
		$this->db->update('options', array('content' => time()), "tags = 'time_update_api_static'");
		return 200;
	}
	public function getVersion()
	{
		$versionapp = $this->db->query("SELECT `content` FROM options WHERE `tags` = 'version'")->row_object()->content;
        return $versionapp;
	}
	
	public function updateVersionDb($version){
		$this->db->update('options', array('content' => $version), "tags = 'version'");
		return 200;
	}
    
    public function getIncentiveProvince()
    {
        $json = $this->db->query("SELECT `content` FROM options WHERE `tags` = 'incentive_province_list'")->row_object()->content;
        foreach(json_decode($json) AS $key => $val){
            $data[$key] = array('id' => $val);
        }
        return $data;
    }
    
    public function updateIncentiveProvinceDb($province)
    {
        $this->db->update('options', array('content' => json_encode(array_unique($province))), "tags = 'incentive_province_list'");
        $this->db->update('options', array('content' => time()), "tags = 'time_update_api_static'");
        return 200;
    }
    
    public function listProvince()
    {
        $sql = "SELECT provinceid AS id,name FROM vn_province";
        $data = $this->db->query($sql)->result_array();
        return $data;
    }

}
